﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WooCoo.Tools;

namespace WooCoo.DataPortal.Server
{
    /// <summary>
    /// 类型与妮称的映射,该类可用于在上下文(C-S)不能传递Type时,需要做映射.
    /// 在程序初始化时添加映射.
    /// </summary>
    public static class TypeFriendlyNameMapper
    {
        public static IDictionary<string, Type> Mapper;
        static TypeFriendlyNameMapper()
        {
            Mapper = new Dictionary<string, Type>();
        }

        public static void SetEntity<T>(string friendlyName)
        {
            if(Mapper.ContainsKey(friendlyName))
            {
                throw Error.InvalidOperation(StringID.CantAddSameFriendlyName.ToLocalStringFormat(friendlyName));
            }
            Mapper.Add(friendlyName, typeof(T));
        }
    }
}
